package com.education.wisdom.controller;

import cn.hutool.core.date.DateUtil;
import com.education.common.utils.ApiReturnObject;
import com.education.common.utils.StringUtils;
import com.education.wisdom.pojo.JrUserConent;
import com.education.wisdom.service.JrUserConentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 达人直播收藏
 */
@RestController
@RequestMapping("/wisdom/JrUserConnet")
public class JrUserConnetController {


    @Autowired
    JrUserConentService jrUserConentService;

    /**
     * 添加数据
     * @param jrUserConent
     * @return
     */
    @PostMapping("/like")
    public ApiReturnObject insert(@RequestBody JrUserConent jrUserConent){
        List<JrUserConent> jrProfeUsers = jrUserConentService.selectJrUserConentList(jrUserConent);
        if (StringUtils.isEmpty(jrProfeUsers)){
            jrUserConent.setCreatetime(DateUtil.date());
            int i = jrUserConentService.insertJrUserConent(jrUserConent);
            return new ApiReturnObject("200", "收藏成功", 1);
        }else {
            int i = jrUserConentService.deleteJrUserConentByIdUserId(jrUserConent);
            return new ApiReturnObject("200", "取消收藏", 0);
        }
    }
}
